<?php

$poll = $this->poll;
$colors = array('#007B31', '#0094DE', '#715497', '#DE107A', '#E6001A', '#E77A1A', '#F1B201');
$colorsCount = count($colors);

?>
<h1>Resultados de la encuesta.</h1>
<p><?php echo $this->escape($poll->question) ?></p>
<table style="width:100%">
<?php
$totalVotes = $poll->votes > 0 ? $poll->votes : 1;
$optionsCount = count($poll->options);
for ($i = 0; $i < $optionsCount; ++$i) {
	$option = $poll->options[$i];
	$color = $colors[$i % $colorsCount];
	$percentLabel = ceil(($option->votes / $totalVotes) * 100) . '%';
?>
		<tr>
			<td><?php echo $this->escape($option->answer) ?></td>
			<td style="width:2em"><?php echo $percentLabel ?></td>
			<td style="width:20em"><div style="background:<?php echo $color ?>;height:16px;width:<?php echo $percentLabel ?>"></div></td>
		</tr>
<?php } ?>
</table>
